<template>
{{#if ctrl.psSysPFPlugin}}
  {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
  <AppExpBar
    v-bind="$attrs"
    :class="classNames">
  {{#if ctrl.showTitleBar}}
    <template #titleBar>
      <div class="control-header__left__caption">
    {{#if ctrl.psSysImage}}
      {{#if ctrl.psSysImage.imagePath}}
        <img src="{{ctrl.psSysImage.imagePath}}"/>
      {{/if}}
      {{#if ctrl.psSysImage.cssClass}}
        <i class="{{ctrl.psSysImage.cssClass}}"></i>
      {{/if}}
    {{/if}}
        <span class="text">\{{model.lanResTag ? $t(model.lanResTag, model.title) : model.title}}</span>
      </div>
    </template>
  {{/if}}
    <template #quickGroup>
      <slot name="quickGroup"></slot>
    </template>
  {{#if ctrl.enableSearch}}
    <template #quickSearch>
        {{> @macro/common/quick-search.hbs placeholder="model.quickSearchPlaceholder"}}
    </template>
  {{/if}}
  {{#ctrl.ctrls}}
    {{#eq controlType 'TOOLBAR'}}
    <template #toolbar>
      {{> @macro/widgets/toolbar/toolbar.hbs ctrl=ctrl}}
    </template>
    {{/eq}}
  {{/ctrl.ctrls}}
    <template #default>
{{#ctrl.ctrls}}
  {{#eq controlType "GRID"}}
      {{> @macro/widgets/grid-detail/grid.hbs ctrl=this singleSelect="true" props=":selectFirstDefault='true'"}}
  {{/eq}}
{{/ctrl.ctrls}}
    </template>
  </AppExpBar>
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@GRIDEXPBAR}}-grid-exp-bar/\{{ctrls@GRIDEXPBAR}}-grid-exp-bar.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
{{#each ctrl.ctrls as | ctrl |}}
    {{#eq controlType "GRID"}}
import {{ctrl.psAppDataEntity.codeName}}{{codeName}}Grid from '@widgets/{{spinalCase ctrl.psAppDataEntity.codeName}}/{{spinalCase codeName}}-grid/{{spinalCase codeName}}-grid.vue';
    {{/eq}}
{{/each}}
{{#hasCtrl ctrl.ctrls 'TOOLBAR'}}
import { AppToolbar } from '@components/widgets/toolbar';
{{/hasCtrl}}
import { AppExpBar } from '@components/widgets/exp-bar';
import { GridExpBarActionType, GridExpBarController, IContext, IGridExpBarAbility, IGridExpBarControllerParams, IGridExpBarStore, IParam, IGridExpBarController, ILoadingHelper, createUUID, IViewCtx } from '@/core';
import {
  useNavParamsBind,
  useEventBind,
  getExpBarClassNames,
{{#hasCtrl ctrl.ctrls 'TOOLBAR'}}
  handleToolbarItemClick,
{{/hasCtrl}}
{{#if ctrl.enableSearch}}
  handleQuickSearch,
{{/if}}
  handleCtrlInit,
  handleCtrlAction,
  handleCtrlDestroy
} from '@/hooks/use-ctrl';
import { model } from './{{spinalCase ctrl.codeName}}-grid-exp-bar-model';
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    "
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="GridExpBarActionType" ability="IGridExpBarAbility"}}

const classNames = computed(() => {
  return getExpBarClassNames(model, props);
});

const controlID = createUUID();

const params: IGridExpBarControllerParams<GridExpBarActionType, IGridExpBarAbility> = {
  name: props.name,
  model,
  evt,
  controlID,
  openView: props.openView,
  newView: props.newView,
  closeView: props.closeView,
  pLoadingHelper: props.pLoadingHelper,
  pViewCtx: props.pViewCtx,
  handler: (data: IGridExpBarStore) => { return reactive(data); }
};
// 表格导航栏控制器
const controller: IGridExpBarController<IGridExpBarStore, IGridExpBarAbility> = new GridExpBarController(params);
useNavParamsBind(controller, props);

const store: IGridExpBarStore = controller.getStore();

onMounted(() => {
  controller.ctrlMounted();
});
onUnmounted(() => {
  controller.ctrlDestroy();
})
</script>